<%@page import="org.jeecgframework.web.util.StaticValue" %>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>HD编辑备件详情页</title>
    <t:base type="jquery,easyui,tools,DatePicker"></t:base>
    <script type="text/javascript" src="plug-in/mutiLang/zh-cn.js"></script>
    <link rel="stylesheet" type="text/css" href="plug-in/accordion/css/accordion.css">
    <script type="text/javascript" src="plug-in/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="plug-in/lhgDialog/lhgdialog.min.js"></script>
    <script type="text/javascript" src="plug-in/jquery-plugs/hftable/jquery-hftable.js"></script>
    <link rel="stylesheet" href="plug-in/jquery/jquery-autocomplete/jquery.autocomplete.css" type="text/css"></link>
    <link rel="stylesheet" href="plug-in/uploadify/css/uploadify.css" type="text/css"/>
    <script type="text/javascript" src="plug-in/uploadify/jquery.uploadify-3.1.min.js"></script>

    <style type="text/css">
        #table thead {
            display: block;
        }

        #table tbody {
            display: block;
            height: 200px;
            overflow: auto;
        }

        .t1 {
            width: 180px;
            min-width: 180px;
            max-width: 180px;
        }

        .t2 {
            width: 180px;
            min-width: 180px;
            max-width: 180px;
        }

        .t3 {
            width: 180px;
            min-width: 180px;
            max-width: 180px;
        }

        .t4 {
            width: 180px;
            min-width: 180px;
            max-width: 180px;
        }

        .t5 {
            width: 180px;
            min-width: 180px;
            max-width: 180px;
        }

        .t6 {
            width: 180px;
            min-width: 180px;
            max-width: 180px;
        }

        .t7 {
            width: 180px;
            min-width: 180px;
            max-width: 180px;
        }

    </style>
    <script type="text/javascript">
        function updateSo(id) {
            var so = $("#so").val();
            $.ajax({
                url: "cbsEquipmentApplyController.do?updateSo",
                data: {
                    "id": id,
                    "so": so
                },
                cache: false,
                dataType: 'json',
                type: 'POST',
                error: function () {// 请求失败处理函数
                },
                success: function (data) {
                    if (data.success) {
                        tip("保存成功");
                    }
                }
            });
        }

        function updateSr(id) {
            var sr = $("#sr").val();
            $.ajax({
                url: "cbsEquipmentApplyController.do?updateSr",
                data: {
                    "id": id,
                    "sr": sr
                },
                cache: false,
                dataType: 'json',
                type: 'POST',
                error: function () {// 请求失败处理函数
                },
                success: function (data) {
                    if (data.success) {
                        $("#sr").val(sr);
                        tip("保存成功");
                    }else{
                        tip("保存失败，SR为空的情况不能保存");
                    }
                }
            });
        }
    </script>
</head>
<body>
<t:formvalid layout="" dialog="false" formid="formobj">
    <div style="margin-bottom:10px;">
        <img style="margin-bottom:-7px" src="plug-in/login/images/dispatch bill.png">
        <span class="list-title">${cbsEquipmentApplyEntity.recordId}</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span style="font-size:13px;">状态：
            <c:if test="${cbsEquipmentApplyEntity.status==1}"><span class="color-red">待审批</span></c:if>
            <c:if test="${cbsEquipmentApplyEntity.status==2}"><span>审批已通过</span></c:if>
            <c:if test="${cbsEquipmentApplyEntity.status==3}"><span>审批未通过</span></c:if>
        </span>
        <div style="position: absolute; text-align: center; width: 100%; margin-top:20px;">
            <input type="hidden" id="warehouseId" value="${cbsEquipmentApplyEntity.warehouseId}">
            <input type="hidden" id="sign" value="${sign}">
            <c:if test="${cbsEquipmentApplyEntity.status==1}">
                <c:if test="${cbsEquipmentApplyEntity.judge!=1}">
                    <a href="#" class="easyui-linkbutton l-btn" onclick="javascript:pass('${id}')">通过</a>
                    <a href="#" class="easyui-linkbutton l-btn" onclick="javascript:notPass('${id}')">不通过</a>
                </c:if>
                <a href="#" class="easyui-linkbutton l-btn" onclick="updateSparepartApply()">保存</a>
            </c:if>
        </div>
    </div>
    <div class="subtitle">
        <p>关联信息</p><c:if test="${code==1}"><span style="color: red">序列号验证未通过，请联系CSA协助核查。</span></c:if>
        <c:if test="${code!=1}"><span style="color: red">序列号验证已通过。</span></c:if>
        <input type="hidden" id="sn" value="${cbsService.sn}">
        <table class="nobordertable noborder">
            <tbody>
            <tr>
                <td class="al_r" width="20%">
                    <label>服务单号CR:</label>
                </td>
                <td width="30%">
                        ${cbsService.code}
                </td>
                <td class="al_r" width="20%">
                    <label>SR:</label>
                </td>
                <td width="30%">
                    <input class="inputxt" name="sr" id="sr" value="${cbsService.sr}"/><a href="#"
                                                                                          class="easyui-linkbutton l-btn"
                                                                                          onclick="updateSr('${id}')">保存</a>
                </td>
            </tr>
            <tr>
                <td class="al_r" width="20%">
                    <label>SO:</label>
                </td>
                <td width="30%">
                    <input class="inputxt" name="so" id="so" value="${cbsService.so}"/><a href="#"
                                                                                          class="easyui-linkbutton l-btn"
                                                                                          onclick="updateSo('${id}')">保存</a>
                </td>
                <td class="al_r" width="20%">

                </td>
                <td width="30%">

                </td>
            </tr>
            <tr>
                <td class="al_r" width="20%">
                    <label>故障代码:</label>
                </td>
                <td width="30%">
                        ${cbsService.errorCode}
                </td>
                <td class="al_r" width="20%">
                   <label>服务描述:</label>
                </td>
                <td width="30%">
 						${cbsService.description}
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="subtitle">
        <p>设备信息</p>
        <input type="hidden" name="id" id="id" value="${cbsEquipmentApplyEntity.id}">
        <table class="nobordertable noborder">
            <tbody>
            <tr>
                <td class="al_r" width="20%">
                    <label>序列号:</label>
                </td>
                <td width="30%">
                    <input class="inputxt" type="hidden" value="${cbsEquipmentApplyEntity.sn}" id="sn"
                           name="zyEquipmentSpareSn"/>
                        ${cbsEquipmentApplyEntity.sn}&nbsp;&nbsp;<span class="color-blue"
                                                                       onclick="viewDetail('${spareId}')">[设备详情]</span>
                </td>
                <td class="al_r" width="20%">
                    <label>机型:</label>
                </td>
                <td width="30%">
                        ${cbsEquipmentApplyEntity.equipmentType}
                </td>
            </tr>
            </tbody>
        </table>
        <div style="margin-top:20px; width: 98%; margin: 10px auto;"><span style="font-weight: bold;">设备历史发货</span>
        </div>
        <table class="ftable" id="table">
            <thead>
            <tr>
                <th class="t1">发货单号</th>
                <th class="t2">备件型号</th>
                <th class="t3">备件号</th>
                <th class="t4">物流</th>
                <th class="t5">预计到货时间</th>
                <th class="t6">发货状态</th>
                <th class="t7">创建时间</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${cbsDelinerEquipmentHql}" var="a">
                <tr>
                    <td class="t1"><span class="color-blue" style="text-decoration: underline"
                                         onclick="addDetailsTab('${a.deliverId.id}')">${a.deliverId.code}</span></td>
                    <td class="t2">${a.typeId.typeDesc}</td>
                    <td class="t3">
                        <c:if test="${a.typeId.typeDesc=='其他'}">${a.equipmentApplyDetailId.item}</c:if>
                        <c:if test="${a.typeId.typeDesc!='其他'}">${a.itemId.item}</c:if>
                    </td>
                    <td class="t4">${a.deliverId.deliverLogistics}</td>
                    <td class="t5">${fn:substring(a.deliverId.expectTime,0,19)}</td>
                    <td class="t6">
                        <c:if test="${a.deliverId.status==1}">CSA待发货</c:if>
                        <c:if test="${a.deliverId.status==2}">CSA已发货</c:if>
                        <c:if test="${a.deliverId.status==3}">CSA取消发货</c:if>
                        <c:if test="${a.deliverId.status==4}">欠货中</c:if>
                        <c:if test="${a.deliverId.status==5}">物流待发货</c:if>
                        <c:if test="${a.deliverId.status==6}">物流待签收</c:if>
                        <c:if test="${a.deliverId.status==7}">已签收</c:if>
                    </td>
                    <td class="t6">${fn:substring(a.deliverId.createDate,0,19)}</td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
    <div class="subtitle">
        <p>备件申请</p>
        <div class="l-div" id="addEquTab">
            <input id="applyId" type="hidden" value="${cbsEquipmentApplyEntity.id}"/>
            <input type="hidden" id="cbsServiceId" value="${cbsEquipmentApplyEntity.serviceId}">
            <c:forEach items="${cbsEquipmentApplyDetailHql}" var="cbs">
                <div style="border-bottom: 1px solid #aeb5ae;" id="div">
                    <table class="nobordertable noborder" style="border: none;" id="${cbs.id}t" name="table">
                        <tbody>
                        <tr>
                            <td class="al_r" width="20%">
                                <span style="color:red;">*</span><label>备件类型:</label>
                            </td>
                            <td width="30%">
                                <input type="hidden" name="applyDetailId" value="${cbs.id}">
                                <input name="typeId" type="hidden" id="${cbs.id}" value="${cbs.typeId.id}"/>
                                <input class="inputxt" name="typeDes" readonly="readonly" uuid="*" type="text"
                                       id="${cbs.id}0" value="${cbs.typeDes}"/>
                                <input value="选择" type="button" onclick="getTree(this,'${cbs.id}')"/>
                            </td>
                            <td class="al_r" width="20%">
                                <span style="color:red;">*</span><label>备件号:</label>
                            </td>
                            <td width="30%">
                                <c:if test="${cbs.typeDes eq '未知备件'}">
                                    <select id="${cbs.id}item" onchange="getItemDesc(this)" name="itemId" datatype="*"
                                            nullmsg="请填写备件号" style="display: none">
                                        <option value="${cbs.itemId.id}">${cbs.item}</option>
                                    </select>
                                    <input name="item" id="${cbs.id}in" type="text" datatype="*" nullmsg="请填写备件号"
                                           value="${cbs.item}">
                                </c:if>
                                <c:if test="${cbs.typeDes != '未知备件'}">
                                    <select id="${cbs.id}item" onchange="getItemDesc(this)" name="itemId" datatype="*"
                                            nullmsg="请填写备件号">
                                        <option value="${cbs.itemId.id}">${cbs.item}</option>
                                    </select>
                                    <input name="item" id="${cbs.id}in" type="text" datatype="*" nullmsg="请填写备件号"
                                           style="display: none" value="${cbs.item}">
                                </c:if>
                            </td>
                        </tr>
                        <tr>
                            <td class="al_r" width="20%">
                                <label>备件描述:</label>
                            </td>
                            <td colspan="3">
                                <c:if test="${cbs.typeId.typeDesc=='未知备件'}"><span class="color-red"
                                                                                  id="${cbs.id}span">${cbs.item}</span><input
                                        type='text' id="${cbs.id}itemDesc" name='itemDesc' style="display: none"></c:if>
                                <c:if test="${cbs.typeId.typeDesc!='未知备件'}"><span class="color-red"
                                                                                  id="${cbs.id}span">${cbs.itemId.itemDesc}</span><input
                                        type='text' id="${cbs.id}itemDesc" name='itemDesc' style="display: none"></c:if>
                            </td>
                        </tr>
                        <tr>
                            <td class="al_r" width="20%">
                                <span style="color:red;">*</span><label>数量:</label>
                            </td>
                            <td width="30%">
                                <input name="total" value="${cbs.total}"/>
                            </td>
                            <td class="al_r" width="20%">
                                <label>申请优先级:</label>
                            </td>
                            <td width="30%">
                                <select name="applyLayer">
                                    <c:forEach items="${tSTypeHql}" var="tst">
                                        <option value="${tst.typecode}" ${tst.typecode==cbs.applyLayer?"selected":""}>${tst.typename}</option>
                                    </c:forEach>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="al_r" width="20%"><label>备件说明:</label></td>
                            <td colspan="3"><textarea name="memo" cols="50">${cbs.memo}</textarea></td>
                        </tr>
                        </tbody>
                    </table>
                    <c:if test="${cbsEquipmentApplyEntity.status==1}">
                        <div style="text-align: right;margin-bottom: 10px">
                            <a class="easyui-linkbutton l-btn" onclick="delSpare('${cbs.id}',this)">删除</a>
                        </div>
                    </c:if>
                </div>
            </c:forEach>
        </div>
        <c:if test="${cbsEquipmentApplyEntity.status==1}">
            <div style="text-align: center;">
                <a class="easyui-linkbutton l-btn" onclick="addEquipment()">添加</a>
            </div>
        </c:if>
        <div style="margin-top:20px;"><span style="font-weight: bold;">说明</span></div>
        <div class="line"></div>
        <table class="nobordertable noborder" style="border: none;">
            <tbody>
            <tr>
                <td class="al_r" width="20%">
                    <label>申请理由:</label>
                </td>
                <td colspan="3">
                    <select id="applyReason">
                        <c:forEach items="${TSTypeList}" var="tst">
                            <option value="${tst.typename}" ${tst.typename==cbsEquipmentApplyEntity.applyReason?"selected":""}>${tst.typename}</option>
                        </c:forEach>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="al_r" width="20%">
                    <label>上传附件:</label>
                </td>
                <td colspan="3">
                    <input type="file" value="上传附件" id="fileUpload"/>&nbsp;&nbsp;
                    <c:forEach items="${fileList}" var="fl">
                        <c:if test="${fl.id!=null}">
                            <p name="fileId" id="li_file_${fl.id}" style="background-color: white"><span class="color-blue"><a
                                style="color: blue"
                                href="fileUploadController.do?downLoadFile&fileLogId=${fl.id}">${fl.oldFileName}</a></span>&nbsp;&nbsp;
                                <a style="cursor: pointer;"
                                   onclick="delFile('${fl.id}','${cbsEquipmentApplyEntity.id}')">[删除]</a>
                            </p>
                        </c:if>
                    </c:forEach>
                </td>
            </tr>
            <tr>
                <td class="al_r" width="20%" valign="top">
                    <label>备注:</label>
                </td>
                <td width="80%">
                    <textarea style="width: 100%; height: 80px;" id="memo">${cbsEquipmentApplyEntity.memo}</textarea>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="subtitle">
        <p>故障备件信息</p>
        <c:if test="${cbsEquipmentApplyEntity.status==1}">
            <a class="easyui-linkbutton l-btn" onclick="faultEquipment()">添加</a>
        </c:if>
        <table class="ftable">
            <tbody id="faultEquipment">
            <tr>
                <th>备件类型</th>
                <th>备件号</th>
                <th>备件序列号</th>
                <th>备件二维码</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${cbsFaultEquipmentList}" var="a">
                <tr id="${a.id}">
                    <td>${a.typeDes}</td>
                    <td>${a.item}</td>
                    <td>${a.sn}</td>
                    <td>${a.equipmentErcode}</td>
                    <td><a class="color-blue" onclick="delFaultEquipment('${a.id}')">[删除]</a></td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
    <div class="subtitle">
        <p>收货人信息</p>
        <table class="nobordertable noborder" style="border: none;">
            <tbody>
            <tr>
                <td class="al_r" width="20%">
                    <label>是否自提:</label>
                </td>
                <td colspan="3">
                    <input type="radio" name="radiobutton" value="是" ${cbsEquipmentApplyEntity.zt==1?"checked":""}
                           onclick="getValue()"> 是
                    <input type="radio" name="radiobutton" value="否" ${cbsEquipmentApplyEntity.zt==2?"checked":""}
                           onclick="getValue()"> 否
                </td>
            </tr>
            <tr>
                <td class="al_r" width="20%">
                    <span style="color:red;">*</span><label>姓名:</label>
                </td>
                <td width="30%">
                    <input id="userName" value="${cbsEquipmentApplyEntity.userName}" datatype="*">
                    <span class="Validform_checktip"></span>
                    <label class="Validform_label" style="display: none;">姓名</label>
                </td>
                <td class="al_r" width="20%">
                    <span style="color:red;">*</span><label>电话:</label>
                </td>
                <td width="30%">
                    <input id="phone" value="${cbsEquipmentApplyEntity.phone}" datatype="*">
                    <span class="Validform_checktip"></span>
                    <label class="Validform_label" style="display: none;">电话</label>
                </td>
            </tr>
            <tr id="tr1">
                <td class="al_r" width="20%">
                    <span style="color:red;">*</span><label>收货地址:</label>
                </td>
                <td width="30%">
                    <select style="width:auto" onchange="getShi()" id="sheng">
                        <option value="">请选择</option>
                        <c:forEach items="${tSTerritoryHql}" var="t">
                            <option value="${t.territoryCode}" ${t.id==cbsEquipmentApplyEntity.sheng.id?"selected":""}>${t.territoryName}</option>
                        </c:forEach>
                    </select>
                    <input type="hidden" id="city" value="${cbsEquipmentApplyEntity.shi.territoryCode}">
                    <select style="width: 45%" id="shi">
                    </select>
                </td>
                <td class="al_r" width="20%">
                    <label>影院名称:</label>
                </td>
                <td width="30%">
                    <input value="${cbsEquipmentApplyEntity.cinemaName}" id="cinemaName">
                </td>
            </tr>
            <tr id="tr2">
                <td></td>
                <td colspan="3" style="padding: 0 8px;">
                    <input id="address" style="width:50%" value="${cbsEquipmentApplyEntity.address}" datatype="*">
                    <span class="Validform_checktip"></span>
                    <label class="Validform_label" style="display: none;">具体地址</label>
                </td>
            </tr>
            <tr id="tr3">
                <td class="al_r"><label>自提仓库:</label></td>
                <td colspan="3">
                    <select id="warehouse" onchange="getWarehouseAddress()">
                    </select>
                    &nbsp;&nbsp;
                    <span id="span"></span>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="subtitle">
        <p>发货信息</p>
        <table class="ftable">
            <tbody>
            <tr>
                <th>发货状态</th>
                <th>预计到货时间</th>
                <th>发货单号</th>
                <th>备件型号</th>
                <th>备件号</th>
                <th>物流</th>
                <th>创建时间</th>
            </tr>
            <c:forEach items="${list}" var="li">
                <c:forEach items="${li}" var="l">
                    <tr>
                        <td>
                            <c:if test="${l.deliverId.status==1}">CSA待发货</c:if>
                            <c:if test="${l.deliverId.status==2}">CSA已发货</c:if>
                            <c:if test="${l.deliverId.status==3}">CSA取消发货</c:if>
                            <c:if test="${l.deliverId.status==4}">欠货中</c:if>
                            <c:if test="${l.deliverId.status==5}">物流待发货</c:if>
                            <c:if test="${l.deliverId.status==6}">物流待签收</c:if>
                            <c:if test="${l.deliverId.status==7}">已签收</c:if>
                        </td>
                        <td>${fn:substring(l.deliverId.expectTime,0,19)}</td>
                        <td>${l.deliverId.code}</td>
                        <td>
                                ${l.typeId.typeDesc}
                        </td>
                        <td>
                            <c:if test="${l.typeId.typeDesc=='其他'}">${l.equipmentApplyDetailId.item}</c:if>
                            <c:if test="${l.typeId.typeDesc!='其他'}">${l.itemId.item}</c:if>
                        </td>
                        <td>${l.deliverId.deliverLogistics}</td>
                        <td>${fn:substring(l.deliverId.createDate,0,19)}</td>
                    </tr>
                </c:forEach>
            </c:forEach>
            </tbody>
        </table>
    </div>
    <div class="subtitle">
        <p>申请人信息</p>
        <table class="nobordertable noborder">
            <tbody>
            <tr>
                <td class="al_r" width="20%">
                    <label>申请人:</label>
                </td>
                <td width="30%">
                        ${cbsEquipmentApplyEntity.createName}
                </td>
                <td class="al_r" width="20%">
                    <label>所属单位:</label>
                </td>
                <td width="30%">
                        ${shortname}
                </td>
            </tr>
            <tr>
                <td class="al_r" width="20%">
                    <label>电话:</label>
                </td>
                <td width="30%">
                        ${mobilePhone}
                </td>
                <td class="al_r" width="20%">

                </td>
                <td width="30%">

                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="subtitle">
        <p>日志</p>
        <table class="ftable">
            <tbody>
            <tr>
                <th>操作人</th>
                <th>时间</th>
                <th>描述</th>
            </tr>
            <c:forEach items="${cbsHandleLogHql}" var="cbs" varStatus="a">
                <c:if test="${a.index<5}">
                    <tr>
                        <td>${cbs.createName}</td>
                        <td>${fn:substring(cbs.createDate,0,19)}</td>
                        <td>${cbs.description}。</td>
                    </tr>
                </c:if>
            </c:forEach>
            </tbody>
        </table>
    </div>
    <div class="subtitle">
        <p>附件列表</p>
        <table class="ftable">
            <tr>
                <th>文件名</th>
                <th>上传时间</th>
                <th>上传人</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${fileList}" var="file">
                <tr>
                    <td>${file.oldFileName}</td>
                    <td><fmt:formatDate value='${file.createDate}' type="date" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                    <td>${file.createName}</td>
                    <td>
                        <span class="color-blue">
                            <a href="fileUploadController.do?downLoadFile&fileLogId=${file.id}">[下载]</a></span>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </div>
</t:formvalid>

<script type="text/javascript">
    if (${cbsEquipmentApplyEntity.zt==2}) {
        $("#tr3").hide();
    } else {
        var warehouseId = $("#warehouseId").val();
        $.ajax({
            url: "cbsServiceController.do?getWarehouse",
            data: {
                "type": 1,
                "id": warehouseId
            },
            cache: false,
            dataType: 'json',
            type: 'POST',
            error: function () {// 请求失败处理函数
            },
            success: function (data) {
                var warehouseHql = data.warehouseHql;
                $("#warehouse").html("");
                var html = "";
                html += "<option value=''>请选择</option>"
                for (var i = 0; i < warehouseHql.length; i++) {
                    html += "<option value='" + warehouseHql[i].id + "'>" + warehouseHql[i].name + "</option>"
                }
                $("#warehouse").append(html);
                $("#warehouse option[value='${cbsEquipmentApplyEntity.warehouseId}']").attr("selected", "selected");
                var a = "";
                var tstList = data.tstList;
                var cbsWarehouse = data.cbsWarehouse;
                if (tstList != null) {
                    for (var i = 0; i < tstList.length; i++) {
                        a += tstList[i][3];
                    }
                    a += cbsWarehouse.address;
                    $("#span").text(a);
                }
            }
        });
        $("#tr1").hide();
        $("#tr2").hide();
    }

    /**
     * 校验非空
     * */
    function jaojan() {
        var flag = true;

        /*备件类型不为空*/
        $("[name='typeDes']").each(function () {
            if($(this).val()==""){
                flag = false;
                tip("备件类型不能为空！");
                return false;
            }
        });

        var itemNo =  $("[name='item']").val();
        /*备件号不为空*/
        $("[name='itemId']").each(function () {
           if(($(this).val()==""||$(this).val()=='请选择')&&itemNo==''){
               flag = false;
               tip("备件号不能为空！");
               return false;
           }
        });


        var isZt = $("[name='radiobutton']:checked").val();
        if (isZt == '是') {  //自提，判断自提仓库是否为空
            var warehouse = $("#warehouse").val();
            if (warehouse == '' || warehouse == null) {
                tip("自提仓库不能为空！");
                flag = false;
            }
        } else { //不自提
            var address = $("#address").val();
            var sheng = $("#sheng").val();
            var shi = $("#shi").val();
            if (sheng == '' || sheng == null) {
                tip("收货省市不能为空！");
                flag = false;
            }
            if (shi == '' || shi == null) {
                tip("收货省市不能为空！");
                flag = false;
            }
            if (address == '' || address == null) {
                tip("收货具体地址不能为空！");
                flag = false;
            }
        }
        return flag;
    }

    /*备件审批通过 id:备件id*/
    function pass(id) {
        if (jaojan()) {
            $.dialog({
                content: "url:cbsEquipmentApplyController.do?goPass&id=" + id,
                zIndex: 100,
                title: '通过：如修改了页面内容，请先保存。',
                lock: true,
                width: '500px',
                height: '300px',
                left: '50%',
                top: '50%',
                opacity: 0.4,
                init: function () {
                    top.myWindow = window;
                },
                button: [{
                    name: '确认',
                    callback: function () {
                        var iframe = this.iframe.contentWindow;
                        var csaAttention = $(iframe.document).find("#csaAttention").val();
                        var engineerAttention = $(iframe.document).find("#engineerAttention").val();
                        var so = $("#so").val();
                        $.ajax({
                            url: "cbsEquipmentApplyController.do?inspectionResult",
                            data: {
                                "id": '${cbsEquipmentApplyEntity.id}'
                            },
                            async: false,
                            cache: false,
                            dataType: 'json',
                            type: 'POST',
                            error: function () {// 请求失败处理函数
                            },
                            success: function (data) {
                                if (data.success) {
                                    $.ajax({
                                        url: "cbsEquipmentApplyController.do?pass",
                                        data: {
                                            "id": id,
                                            "csaAttention": csaAttention,
                                            "engineerAttention": engineerAttention,
                                            "so": so
                                        },
                                        async: false,
                                        cache: false,
                                        dataType: 'json',
                                        type: 'POST',
                                        error: function () {// 请求失败处理函数
                                        },
                                        success: function (data) {
                                            if (data.success) {
                                                addOneTab("备件审批管理", "cbsEquipmentApplyController.do?cbsEquipmentApply&type=2", "");
                                                closetab('备件申请详情页' + data.msg);
                                            }else{
                                                tip(data.msg);
                                            }
                                        }
                                    });
                                } else {
                                    tip("状态已更新，请刷新页面");
                                }
                            }
                        });
                    },
                    focus: true
                }, {
                    name: '取消',
                    callback: function () {
                    }
                }]
            });
        }
    }

    /*审批不通过*/
    function notPass(id) {
        if (jaojan()) {
            $.dialog({
                content: "url:cbsEquipmentApplyController.do?goNotPass&id=" + id,
                zIndex: 100,
                title: '不通过：如修改了页面内容，请先保存。',
                lock: true,
                width: '500px',
                height: '300px',
                left: '50%',
                top: '50%',
                opacity: 0.4,
                init: function () {
                    top.myWindow = window;
                },
                button: [{
                    name: '确认',
                    callback: function () {
                        var iframe = this.iframe.contentWindow;
                        var reasion = $(iframe.document).find("#reasion").val();
                        $.ajax({
                            url: "cbsEquipmentApplyController.do?inspectionResult",
                            data: {
                                "id": '${cbsEquipmentApplyEntity.id}'
                            },
                            async: false,
                            cache: false,
                            dataType: 'json',
                            type: 'POST',
                            error: function () {// 请求失败处理函数
                            },
                            success: function (data) {
                                if (data.success) {
                                    $.ajax({
                                        url: "cbsEquipmentApplyController.do?notPass",
                                        data: {
                                            "id": id,
                                            "reasion": reasion
                                        },
                                        cache: false,
                                        dataType: 'json',
                                        type: 'POST',
                                        error: function () {// 请求失败处理函数
                                        },
                                        success: function (data) {
                                            if (data.success) {
                                                addOneTab("备件审批管理", "cbsEquipmentApplyController.do?cbsEquipmentApply&type=2", "");
                                                closetab('备件申请详情页' + data.msg);
                                            }else{
                                                tip(data.msg);
                                            }
                                        }
                                    });
                                } else {
                                    tip("状态已更新，请刷新页面");
                                }
                            }
                        });
                    },
                    focus: true
                }, {
                    name: '取消',
                    callback: function () {
                    }
                }]
            });
        }
    }

    function addEquipment() {
        $.ajax({
            url: "cbsServiceController.do?getUuid",
            cache: false,
            dataType: 'json',
            type: 'POST',
            error: function () {// 请求失败处理函数
            },
            success: function (uuid) {
                var html = '<div style="border-bottom: 1px solid #aeb5ae;" id="' + uuid + 'div"><table class="nobordertable noborder" name="table" id="' + uuid + 't" style="border: none;">' +
                    '<tbody><tr><td class="al_r" width="20%"><span style="color:red;">*</span><label>备件类型:</label></td><td width="30%">' +
                    '<input name="typeId" type="hidden" id="' + uuid + '" />' +
                    '<input class="inputxt" name="typeDes" id="' + uuid + '0" readonly="readonly" uuid="*" />' +
                    '<input class="button" value="选择" type="button" id="' + uuid + '" onclick="getTree(this,null)"/>' +
                    '</td><td class="al_r" width="20%">' +
                    '<span style="color:red;">*</span><label>备件号:</label></td><td width="30%"><select name="itemId" id="' + uuid + 'item" datatype="*" onchange="getItemDesc(this)"><option value="">请选择</option></select><span class="Validform_checktip"></span><label class="Validform_label" style="display: none;">备件号</label><input name="item" datatype="*" nullmsg="请填写备件号" id="' + uuid + 'in" type="text" style="display: none"></td>' +
                    '</tr><tr><td class="al_r" width="20%"><label>备件描述:</label></td><td colspan="3">' +
                    '<span class="color-red" id="' + uuid + 'span"></span><input type="text" id="' + uuid + 'itemDesc" name="itemDesc" style="display: none"></td></tr><tr><td class="al_r" width="20%">' +
                    '<span style="color:red;">*</span><label>数量:</label></td><td width="30%"><input name="total" /></td><td class="al_r" width="20%">' +
                    '<span style="color:red;">*</span><label>申请优先级:</label></td><td width="30%"><select name="applyLayer"><option value="1">低</option><option value="2" selected="selected">中</option><option value="3">高</option><option value="4">加急</option></select>' +
                    '</td></tr><tr><td class="al_r" width="20%"><label>备件说明:</label></td><td colspan="3">' +
                    '<textarea name="memo" cols="50"></textarea></td></tr></tbody></table><div style="text-align: right;margin-bottom: 10px">' +
                    '<a class="easyui-linkbutton l-btn" onclick=delSparePart("' + uuid + '",this)><span class="l-btn-left"><span class="l-btn-text">删除</span></span></a></div></div>';
                console.log(html);
                $("#addEquTab").append(html);
            }
        });
    }

    function delSparePart(uuid, obj) {
        $("#" + uuid + "div").remove();
    }

    function delSpare(applyDetailId, obj) {
        $.dialog.confirm('删除操作即时生效，请确认是否删除？', function (r) {
            if (r) {
                $.ajax({
                    url: "cbsEquipmentApplyController.do?delSpare",
                    data: {
                        "applyDetailId": applyDetailId,
                    },
                    cache: false,
                    dataType: 'json',
                    type: 'POST',
                    error: function () {// 请求失败处理函数
                    },
                    success: function (data) {
                        if (data.success) {
                            $("#" + applyDetailId + "t").remove();
                            $(obj).remove();
                        }
                    }
                });
            }
        });
    }

    function getTree(obj, id) {
        var uuid = obj.id;
        var aId = '${cbsEquipmentApplyEntity.id}'
        $.dialog({
            content: "url:cbsEquipmentApplyController.do?goChooseEquipmentType&uuid=" + uuid + "&id=" + id + "&aId=" + aId,
            zIndex: 2100,
            title: '机型',
            lock: true,
            width: '300px',
            height: '400px',
            left: '85%',
            top: '65%',
            opacity: 0.4,
            init: function () {
                top.myWindow = window;
            },
        });
    }

    function getItemDesc(obj) {
        var uuid = obj.id.substring(0, 32);
        $.ajax({
            url: "cbsServiceController.do?getItemDesc",
            data: {
                "id": obj.value,
            },
            cache: false,
            dataType: 'json',
            type: 'POST',
            error: function () {// 请求失败处理函数
            },
            success: function (data) {
                if (uuid != null) {
                    $("#" + uuid + "span").text(data.itemDesc);
                } else {
                    $("#" + obj.id + "span").text(data.itemDesc);
                }

            }
        });
    }

    function getValue() {
        var radiobutton = $("[name='radiobutton']:checked").val();
        if (radiobutton == '是') {
            $.ajax({
                url: "cbsServiceController.do?getWarehouse",
                cache: false,
                dataType: 'json',
                type: 'POST',
                error: function () {// 请求失败处理函数
                },
                success: function (data) {
                    var warehouseHql = data.warehouseHql;
                    $("#warehouse").html("");
                    var html = "";
                    for (var i = 0; i < warehouseHql.length; i++) {
                        html += "<option value='" + warehouseHql[i].id + "' >" + warehouseHql[i].name + "</option>"
                    }
                    $("#warehouse").append(html);
                }
            });
            $("#tr1").hide();
            $("#tr2").hide();
            $("#tr3").show();
        } else {
            getShi();
            $("#tr1").show();
            $("#tr2").show();
            $("#tr3").hide();
        }
    }

    function getShi() {
        var sheng = $("#sheng").val();
        $.ajax({
            url: "cbsServiceController.do?getShi",
            data: {
                "sheng": sheng,
            },
            cache: false,
            dataType: 'json',
            type: 'POST',
            error: function () {// 请求失败处理函数
            },
            success: function (data) {
                $("#shi").html("");
                var html = "";
                html += "<option value=''>请选择</option>";
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i].territoryCode + "'>" + data[i].territoryName + "</option>"
                }
                $("#shi").append(html);
                var shi = $("#shi").find("option");
                var city = $("#city").val();
                for (var j = 0; j < shi.length; j++) {
                    if ($(shi[j]).val() == city) {
                        $(shi[j]).attr("selected", "selected");
                    }
                }
            }
        });
    }

    function getWarehouseAddress() {
        var id = $("#warehouse").val();
        var type = 1;
        $.ajax({
            url: "cbsServiceController.do?getWarehouse",
            data: {
                "type": type,
                "id": id
            },
            cache: false,
            dataType: 'json',
            type: 'POST',
            error: function () {// 请求失败处理函数
            },
            success: function (data) {
                var a = "";
                var tstList = data.tstList;
                var cbsWarehouse = data.cbsWarehouse;
                if (tstList != null) {
                    for (var i = 0; i < tstList.length; i++) {
                        a += tstList[i][3];
                    }
                    a += cbsWarehouse.address;
                    $("#span").text(a);
                }
            }
        });
    }

    function updateSparepartApply() {
        var fl = $("[name='fileId']").length;
        if (fl > 3) {
            tip("最多上传三张照片");
            return;
        }
        var table = $("[name='table']");
        if (table.length == 0) {
            tip("请至少添加一个备件");
            return;
        }
        var panduan = 0;
        $("[name='typeDes']").each(function () {
            if ($(this).val() == null || $(this).val() == "") {
                panduan = 1;
            }
        });
        if (panduan == 1) {
            tip("备件类型不能为空");
            return;
        }

        $("[name='total']").each(function () {
            if (isNaN($(this).val())) {
                panduan = 4;
            }
        });
        if (panduan == 4) {
            tip("数量必须为数字");
            return;
        }
        $("[name='total']").each(function () {
            if ($(this).val() == null || $(this).val() == "") {
                panduan = 3;
            }
        });
        if (panduan == 3) {
            tip("数量不能为空");
            return;
        }
        var sheng = $("#sheng").val();
        var shi = $("#shi").val();
        if (sheng == '' || shi == '') {
            tip("收货地址不能为空");
            return false;
        }
        //调用formValidata 进行验证，并能阻止提交
        if (!form.check(true)) {
            form.submitForm(false);
            var a = $("input,select:focus").attr("id");
            $("html,body").animate({scrollTop: $("#" + a).offset().top + (-100) + "px"}, "fast");
            return;
        }
        var sign = $("#sign").val();
        if (sign != 1) {
            sign = 0;
        }
        if (${cbsEquipmentApplyEntity.status==1}) {
            var recordId = '${cbsEquipmentApplyEntity.recordId}';
            var obj = {};
            obj.id = $("#id").val();
            obj.radiobutton = $("[name='radiobutton']:checked").val();
            obj.sn = $("#sn").val();
            obj.equipmentType = $("#equipmentType").val();
            obj.userName = $("#userName").val();
            obj.phone = $("#phone").val();
            obj.cinemaName = $("#cinemaName").val();
            obj.applyReason = $("#applyReason").val();
            obj.memo = $("#memo").val();
            obj.sheng = $("#sheng").val();
            obj.shi = $("#shi").val();
            obj.warehouse = $("#warehouse").val();
            obj.serviceId = $("#cbsServiceId").val();
            obj.aid = $("#applyId").val();
            obj.address = $("#address").val();
            obj.so = $("#so").val();
            obj.sr = $("#sr").val();
            var typeIds = [];
            var m = 0;
            $("[name='typeId']").each(function () {
                typeIds[m] = $(this).val();
                m++;
            });
            var typeDess = [];
            var s = 0;
            $("[name='typeDes']").each(function () {
                typeDess[s] = $(this).val();
                s++;
            });
            var itemIds = [];
            var u = 0;
            $("[name='itemId']").each(function () {
                itemIds[u] = $(this).val();
                u++;
            });
            var items = [];
            var e = 0;
            $("[name='item']").each(function () {
                items[e] = $(this).val();
                e++;
            });
            var totals = [];
            var c = 0;
            $("[name='total']").each(function () {
                totals[c] = $(this).val();
                c++;
            });
            var applyLayers = [];
            var x = 0;
            $("[name='applyLayer']").each(function () {
                applyLayers[x] = $(this).val();
                x++;
            });
            var memos = [];
            var y = 0;
            $("[name='memo']").each(function () {
                memos[y] = $(this).val();
                y++;
            });
            var applyDetailIds = [];
            var l = 0;
            $("[name='applyDetailId']").each(function () {
                applyDetailIds[l] = $(this).val();
                l++;
            });
            var fileIds = [];
            var p = 0;
            $("[name='fileId']").each(function () {
                fileIds[p] = this.id.substr(8, 32);
                p++;
            });
            obj.fileIds = fileIds;
            obj.typeIds = typeIds;
            obj.applyDetailIds = applyDetailIds;
            obj.typeDess = typeDess;
            obj.itemIds = itemIds;
            obj.items = items;
            obj.totals = totals;
            obj.applyLayers = applyLayers;
            obj.memos = memos;
            var type_ids = [];
            var a = 0;
            $("[name='type_id']").each(function () {
                type_ids[a] = $(this).val();
                a++;
            });
            var type_dess = [];
            var b = 0;
            $("[name='type_des']").each(function () {
                type_dess[b] = $(this).val();
                b++;
            });
            var item_ids = [];
            var f = 0;
            $("[name='item_id']").each(function () {
                item_ids[f] = $(this).val();
                f++;
            });
            var itemms = [];
            var g = 0;
            $("[name='itemm']").each(function () {
                itemms[g] = $(this).val();
                g++;
            });
            var s_ns = [];
            var h = 0;
            $("[name='s_n']").each(function () {
                s_ns[h] = $(this).val();
                h++;
            });
            var equipment_ercodes = [];
            var j = 0;
            $("[name='equipment_ercode']").each(function () {
                equipment_ercodes[j] = $(this).val();
                j++;
            });
            obj.type_ids = type_ids;
            obj.type_dess = type_dess;
            obj.item_ids = item_ids;
            obj.itemms = itemms;
            obj.s_ns = s_ns;
            obj.equipment_ercodes = equipment_ercodes;
            obj.sign = sign;

            /*保存之前先检查是否已经审批*/
            $.ajax({
                url: "cbsEquipmentApplyController.do?inspectionResult",
                data: {
                    "id": '${cbsEquipmentApplyEntity.id}'
                },
                async: false,
                cache: false,
                dataType: 'json',
                type: 'POST',
                error: function () {// 请求失败处理函数
                },
                success: function (data) {
                    if (data.success) {
                        $.ajax({
                            url: "cbsEquipmentApplyController.do?updateSparepartApply",
                            data: obj,
                            cache: false,
                            dataType: 'json',
                            type: 'POST',
                            async: false,
                            traditional: true,
                            success: function (data) {
                                if (data.success) {
                                    if (data.msg == 1) {
                                        addOneTab('我的任务', 'cbsServiceAssignListController.do?engineerlists&code=1', '');
                                        closetab('备件申请详情页' + recordId);
                                    } else {
                                        addOneTab('备件审批管理', 'cbsEquipmentApplyController.do?cbsEquipmentApply&type=1', '');
                                        closetab('备件申请详情页' + recordId);
                                    }
                                }
                            }
                        });
                    } else {
                        tip("状态已更新，请刷新页面");
                    }
                }
            });


        } else {
            tip("该单不是待审批状态，不能修改");
        }
    }

    $(function () {
        var cbsServiceId = $("#cbsServiceId").val();
        $("#fileUpload").uploadify({
            buttonText: '继续上传',
            auto: true,
            progressData: 'speed',
            multi: true,
            height: 20,
            width: 60,
            overrideEvents: ['onDialogClose'],
            queueID: 'instructionfile',
            fileTypeDesc: '文件格式:',
            fileTypeExts: '*.*',
            queueSizeLimit: '3',
            fileSizeLimit: '50MB',
            swf: 'plug-in/uploadify/uploadify.swf',
            uploader: 'cbsServiceController.do?fileUploadView&cbsServiceId=' + cbsServiceId + "&businessType=F",
            onUploadStart: function () {
                lockmask(true, '请稍等,导入中...');
            },
            onUploadSuccess: function (file, data) {
                lockmask(false);
                var json = $.parseJSON(data).attributes;
                console.log(json.id + "--" + json.name);
                var html = '<p name="fileId" id="li_file_' + json.id + '" style="background-color: white"><span class="color-blue" id="' + json.id + '">' + json.name + '</span>&nbsp;&nbsp; ' +
                    '<span style="cursor: pointer; color: black" onclick=delFile("' + json.id + '",null)>[删除]</span></p>';
                $("#fileUpload").after(html);
                tip("上传成功！");
            }, onFallback: function () {
                tip("您未安装FLASH控件，无法上传文件！请安装FLASH控件后再试");
            }, onSelectError: function (file, errorCode, errorMsg) {
                switch (errorCode) {
                    case -100:
                        tip("上传的文件数量已经超出系统限制的" + $('#fileUpload').uploadify('settings', 'queueSizeLimit') + "个文件！");
                        break;
                    case -110:
                        tip("文件 [" + file.name + "] 大小超出系统限制的50MB大小！");
                        break;
                    case -120:
                        tip("文件 [" + file.name + "] 大小异常！");
                        break;
                    case -130:
                        tip("文件 [" + file.name + "] 类型不正确！");
                        break;
                }
            }
        });
    });

    function delFile(fileId, applyId) {
        var flag = true;
        $.ajax({
            url: "cbsEquipmentApplyController.do?delFile",
            data: {
                "id": fileId,
                "applyId": applyId
            },
            cache: false,
            dataType: 'json',
            type: 'POST',
            async: false,
            success: function (data) {
                if (!data.success) {
                    flag = false;
                    tip(data.msg);
                } else {
                    tip(data.msg);
                    //隐藏标签
                    $("#li_file_" + fileId + "").remove();
                }
            }
        });
    }


    function delFaultEquipment(id) {
        $.ajax({
            url: "cbsEquipmentApplyController.do?delFaultEquipment",
            data: {
                "id": id,
            },
            cache: false,
            dataType: 'json',
            type: 'POST',
            async: false,
            success: function (data) {
                if (!data.success) {
                    flag = false;
                    tip(data.msg);
                } else {
                    tip(data.msg);
                    //隐藏标签
                    $("#" + id + "").remove();
                }
            }
        });
    }

    function faultEquipment() {
        $.ajax({
            url: "cbsServiceController.do?getUuid",
            cache: false,
            dataType: 'json',
            type: 'POST',
            error: function () {// 请求失败处理函数
            },
            success: function (uuid) {
                var html = '<tr id="' + uuid + 'tr"><td><input name="type_id" type="hidden" id="' + uuid + '"/>' +
                    '<input class="inputxt" name="type_des" readonly="readonly" id="' + uuid + '0" datatype="*" />' +
                    '<input class="button" value="选择" type="button" id="' + uuid + '" onclick="getTree1(this)"/></td>' +
                    '<td><select name="item_id" id="' + uuid + 'item"><option value="0">请选择</option></select><input name="itemm" id="' + uuid + 'in" type="text" style="display: none"></td>' +
                    '<td><input name="s_n" type="text"></td>' +
                    '<td><input name="equipment_ercode" type="text"></td>' +
                    '<td><a class="color-blue" onclick=delEquipment("' + uuid + '")>[删除]</a></td>' +
                    '</tr>';
                console.log(html);
                $("#faultEquipment").append(html);
            }
        });
    }

    function delEquipment(uuid) {
        $("#" + uuid + "tr").remove();
    }

    function getTree1(obj) {
        var uuid = obj.id;
        var aId = '${cbsEquipmentApplyEntity.id}';
        $.dialog({
            content: "url:cbsEquipmentApplyController.do?goChooseEquipmentType&uuid=" + uuid + "&aId=" + aId,
            zIndex: 2100,
            title: '机型',
            lock: true,
            width: '300px',
            height: '400px',
            left: '85%',
            top: '65%',
            opacity: 0.4,
            init: function () {
                top.myWindow = window;
            },
        });
    }

    /*设备详情*/
    function viewDetail(id) {
        if (null != id && id != '') {
            addOneTab('设备详细', 'zyEquipmentSpareController.do?goView&id=' + id);
        } else {
            tip("设备不存在！");
        }
    }

    /*发货单详情*/
    function addDetailsTab(id) {
        addOneTab("发货单详情", "cbsDelinerController.do?goDeliverDetails&id=" + id + "");
    }

    $(function () {
        getShi();
    })
    var form = $("#formobj").Validform({
        ignoreHidden: true,
        postonce: true,
        showAllError: true,
        ajaxPost: true,
        tiptype: 3,
    })
</script>
</body>
</html>